package com.ruoyi.project.remake.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.common.utils.BarCodeUtils;
import com.ruoyi.project.remake.domain.PayMent;
import com.ruoyi.project.remake.domain.TCaseMain;
import com.ruoyi.project.remake.domain.vo.CaseMainVo;
import com.ruoyi.project.remake.service.IPayMentService;
import com.ruoyi.project.remake.service.ITCaseMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.remake.mapper.ApplyDocumentMapper;
import com.ruoyi.project.remake.domain.ApplyDocument;
import com.ruoyi.project.remake.service.IApplyDocumentService;

/**
 * 申请单据Service业务层处理
 *
 * @author 孙山伟
 * @date 2023-03-28
 */
@Service
public class ApplyDocumentServiceImpl implements IApplyDocumentService
{
    @Autowired
    private ApplyDocumentMapper applyDocumentMapper;
    @Autowired
    private ITCaseMainService tCaseMainService;
    @Autowired
    private IPayMentService payMentService;
    /**
     * 查询申请单据
     *
     * @param id 申请单据ID
     * @return 申请单据
     */
    @Override
    public ApplyDocument selectApplyDocumentById(Long id)
    {
        return applyDocumentMapper.selectApplyDocumentById(id);
    }

    /**
     * 查询申请单据列表
     *
     * @param applyDocument 申请单据
     * @return 申请单据
     */
    @Override
    public List<ApplyDocument> selectApplyDocumentList(ApplyDocument applyDocument)
    {
        return applyDocumentMapper.selectApplyDocumentList(applyDocument);
    }

    /**
     * 新增申请单据
     *
     * @param applyDocument 申请单据
     * @return 结果
     */
    @Override
    public int insertApplyDocument(ApplyDocument applyDocument)
    {
        applyDocument.setCreateTime(DateUtils.getNowDate());
        return applyDocumentMapper.insertApplyDocument(applyDocument);
    }

    /**
     * 修改申请单据
     *
     * @param applyDocument 申请单据
     * @return 结果
     */
    @Override
    public int updateApplyDocument(ApplyDocument applyDocument)
    {
        return applyDocumentMapper.updateApplyDocument(applyDocument);
    }

    /**
     * 批量删除申请单据
     *
     * @param ids 需要删除的申请单据ID
     * @return 结果
     */
    @Override
    public int deleteApplyDocumentByIds(Long[] ids)
    {
        return applyDocumentMapper.deleteApplyDocumentByIds(ids);
    }

    /**
     * 删除申请单据信息
     *
     * @param id 申请单据ID
     * @return 结果
     */
    @Override
    public int deleteApplyDocumentById(Long id)
    {
        return applyDocumentMapper.deleteApplyDocumentById(id);
    }

    @Override
    public Map<String, Object> getApply(Long id) {
        Map<String, Object> result=new HashMap<>();
        ApplyDocument  applyDocument=applyDocumentMapper.selectApplyDocumentById(id);
        CaseMainVo caseMain=tCaseMainService.selectTCaseMainById(applyDocument.getCaseMainId());
        PayMent payMent=payMentService.selectPayMentById(applyDocument.getPayMent());
        //上方的条形码
        result.put("qrCode", BarCodeUtils.getBarCodeImageBaseCode(caseMain.getCardNumber()));
        //患者姓名
        result.put("patientName", caseMain.getPatientsName());
        //患者性别
        result.put("sex", caseMain.getPatientsGender());
        //患者性别
        result.put("idCard", caseMain.getIdentityCard());
        //出院日期,
        result.put("dischargeTime",caseMain.getDischargeTime());
        //出院科室
        result.put("leaveDepartment", caseMain.getLeaveDepartment());
        //病案号
        result.put("cardNumber", caseMain.getCardNumber());
        //住院号
        result.put("admissionNumber", caseMain.getAdmissionNumber());
        //申请原因
        result.put("copyCause", applyDocument.getCopyCause());
        result.put("fileNumber",payMent.getFileNumber());
        //总金额
        result.put("totalMoney",payMent.getTotalMonney().toString());
        //申请人
        result.put("applyName",applyDocument.getApplyName());
        //申请人身份证
        result.put("applyCard",applyDocument.getCard());
        //申请人关系
        result.put("relations",applyDocument.getRelations());
        //审批者
        result.put("qualityName",caseMain.getQualityName());
        result.put("levelDate",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date()));
        return result;
    }
}
